package com.hapoerpejb.services;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;


/**
 * Session Bean implementation class UserDao
 */
@Stateless
public class UserDaoImpl implements UserDaoRemote, UserDaoLocal {

    /**
     * Default constructor. 
     */
	@PersistenceContext(unitName ="HAPOERP_EJB")
	EntityManager em;
	
    public UserDaoImpl() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public int findByUserAndPwd(String user, String pwd) {
	
		try
		{
			return (Integer) em.createNamedQuery("User.findByUserAndPwd").setParameter("var", user).setParameter("var1", pwd).getSingleResult();
		}
		catch(NoResultException e)
		{
			return 0;
		}
	}
}